<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <title>用户登录</title>
    <link rel="stylesheet" href="/static/common/layui/css/layui.css"/>
    <script language="javascript">
        //禁止别的Iframe首页
        if (top.location !== self.location) {
            top.location = self.location;
        }
    </script>
</head>
<body>
<form action="" method="post" class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名：</label>
        <div class="layui-input-inline">
            <input class="layui-input" placeholder="请输入用户名" name="username"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码：</label>
        <div class="layui-input-inline">
            <input type="password" class="layui-input" name="password" placeholder="请输入密码"/>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-danger" lay-filter="login" lay-submit="submit">登录</button>
        </div>
    </div>
</form>

<script type="text/javascript" src="/static/common/axios.min.js"></script>
<script type="text/javascript" src="/static/common/jquery-3.2.1.js"></script>
<script type="text/javascript" src="/static/common/layui/layui.js"></script>
<script>
layui.use(['layer','form'],function () {
    var layer = layui.layer,
        form = layui.form;

    form.on("submit(login)",function (data) {
        var LoginInfo = {
            username:data.field.username,
            password:data.field.password,
        };
        axios.post("/toLogin",LoginInfo)
            .then(function (response) {
                console.log(response);
                if(response.data.success) {
                    location.href = "/index";
                }
                else{
                    layer.msg(response.data.msg,{icon:2});
                }
            })
            .catch(function (msg) {
                console.log(msg);
            });
        return false;
    });
});
</script>
</body>
</html>